//
//  TGSystemMacros.h
//  TongGuanLease
//
//  Created by 张奇 on 2022/4/12.
//

#ifndef TGSystemMacros_h
#define TGSystemMacros_h

//通知
#define kNSNotificationCenter [NSNotificationCenter defaultCenter]
/**
 *  获取物理屏幕尺寸
 */
#define PhoneScreen_HEIGHT [UIScreen mainScreen].bounds.size.height
#define PhoneScreen_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))

#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)

#define SELFWIDTH self.frame.size.width
#define SELFHEIGHT self.frame.size.height


#define HeaderBannerHeight  RatioHeight(183)
/**
 *  计算代码运行时间
 */
#define LD_START_TIMER NSDate *startTime = [NSDate date];
#define LD_END_TIMER NSLog(@"Time: %f", -[startTime timeIntervalSinceNow]);


/**
 *  NSLog宏定义
 */

#if DEBUG
#define NSLog(format, ...) do {                                                                          \
fprintf(stderr, "<%s : %d> %s\n",                                           \
[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String],  \
__LINE__, __func__);                                                        \
(NSLog)((format), ##__VA_ARGS__);                                           \
\
} while (0)
#else
#define NSLog(...)
#endif

//#define NSLog(format, ...) printf("\n[%s] %s [第%d行] \n %s", __TIME__, __FUNCTION__, __LINE__, [[NSString stringWithFormat:format, ## __VA_ARGS__] UTF8String]);
#define  adjustsScrollViewInsets_NO(scrollView,vc)\
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
if ([UIScrollView instancesRespondToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {\
if ([scrollView isKindOfClass:[UIScrollView class]]){\
[scrollView   performSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:") withObject:@(2)];\
}\
} else {\
}\
_Pragma("clang diagnostic pop") \
} while (0)

#define String(m) [NSString stringWithFormat:@"%@",@(m)]
#define StringFormat(m,n) [NSString stringWithFormat:@"%@%@",m,n]
#define StringChar(m) [NSString stringWithFormat:@"%@",m]
#define APPDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate)

#define R(A)  A?A:@""

/**
 *  字体等比缩放
 */
/**
 *  4 320:480
 *  5 320:568
 *  6 375:667 750x1334
 *  6p 414:736
 */
#define RWidth 375
#define RHeight 667
#define kScreenWidthRatio  (SCREEN_WIDTH / RWidth)
#define kScreenHeightRatio (PhoneScreen_HEIGHT / RHeight)
#define AdaptedWidthValue(x)  (ceilf((x) * kScreenWidthRatio))
#define AdaptedHeightValue(x) (ceilf((x) * kScreenHeightRatio))
//推送开关
#define PUSH_SWITCH @"PUSH_SWITCH"

#define PAY_TYPE_DEFALUT StringFormat(@"PAY_TYPE_DEFALUT")
//声音
#define PUSH_VOICE_SWITCH StringFormat(@"PUSH_VOICE_SWITCH",@"-0")
//震动
#define PUSH_SHAKE_SWITCH StringFormat(@"PUSH_SHAKE_SWITCH",@"-0")
//拨钱
#define PUSH_MONEY_SWITCH StringFormat(@"PUSH_MONEY_SWITCH",@"-0")


//平方字体
#define Ping_Medium  @"PingFangSC-Medium" //
#define Ping_Regular @"PingFangSC-Regular"
#define Ping_Bold    @"PingFangSC-Semibold"
#define Ping_Light    @"PingFangSC-Light"
#define Ping_Thin    @"PingFangSC-Thin"
#define Ping_Semibold    @"PingFangSC-Semibold"
#define Ping_Heavy    @"PingFangSC-Heavy"

#define Zero(data)  (data ? data : @"0")


#define WEAK  @weakify(self);
#define STRONG  @strongify(self);
#define WEAKSELF(weakSelf)  __weak __typeof(&*self)weakSelf = self;

#pragma mark -  判空处理
/** 字符串是否为空*/
#define PCBStringIsEmpty(str) ([str isKindOfClass:[NSNull class]]||[str isEqual:[NSNull null]]||[str isEqualToString:@"null"] || str == nil||[[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]==0|| [str length] < 1 ? YES : NO )

/** 数组是否为空*/
#define PCBArrayIsEmpty(array) ((array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0) ? YES : NO)
/** 字典是否为空*/
#define PCBDictIsEmpty(dic) ((dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys.count == 0) ? YES : NO)

/**  隐藏键盘*/
#define HidenKeybory {[[[UIApplication sharedApplication] keyWindow] endEditing:YES];}

/**  设置颜色RGB值*/
#define RGBA(R,G,B,A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]

#define RGB(R,G,B) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1]
#define RGBCOLOR(r,g,b,_alpha) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:_alpha]
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]



//验证码重发时间限制
#define CodeTimeCount 60
//验证码发送时间归档名称
#define CodeDateSave @"DateSave"
#define NetworkError @"网络出错了，请重新尝试"

#pragma mark - Load Image
#define kImage(Name) ([UIImage imageNamed:Name])
#define kImageOfFile(Name) ([UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:Name ofType:nil]])
#define kImageOfLDFile(Name) ([UIImage imageLDNamed:Name])

#define PlaceHolderImage [UIImage imageNamed:@"common_placehoder"]
#define PlaceYuanHolderImage [UIImage imageNamed:@"yuanzhanwei"]

// 头像展位图
#define IconPlaceHolderImage kImage(@"mine_icon_in")

#define AutoBlodFont(F) [LZT_UIHelper boldFontOfSize:F]
#define AutoHeight(F) [LZT_UIHelper autoHeight:F]
#define GOODS_CELL_LEFT_MARGIN 5

/**去除警告*/
#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)
/**默认头像*/
#define MM_BUNDLE_IMAGE(name) [UIImage imageNamed:[NSString stringWithFormat:@"makeMoney.bundle/%@",name]]
#define MM_BUNDLE_IMAGE_STRING(name) [NSString stringWithFormat:@"makeMoney.bundle/%@",name]
#define HUD_DEFAULT_TIME 2.0

#define APNS_TOKEN @"APNSTOKEN"
/**cache 名称*/
#define ADDRESSCache @"AddressCacha"

#define AddressAd @"address_ad"
//padd
#define NX_PADD RatioWidth(15)
#define X_PADD RatioWidth(20)
#define Y_PADD RatioHeight(10)

// 防止多次调用
#define kPreventRepeatClickTime(_seconds_) \
static BOOL shouldPrevent; \
if (shouldPrevent) {\
return;\
}\
shouldPrevent = YES; \
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((_seconds_) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ \
shouldPrevent = NO; \
}); \

#endif /* TGSystemMacros_h */
